package course.java.hr;

import java.io.Serializable;

public class Employee extends TaxableEntity implements Serializable
{
	private static final long serialVersionUID = 1L;

	public static final float TAX_RATE = .0765f;

	private float salary;
	private float ytdSalary;
	private float ytdTax = 0;

	private PAYTYPE ptype = PAYTYPE.HOURLY;

//	private void writeObject(java.io.ObjectOutputStream out) throws IOException
//	{
//		out.writeObject(getName());
//		out.writeObject(getTaxId());
//		//...
//		
//	}
//
//	private void readObject(java.io.ObjectInputStream in) throws IOException,
//			ClassNotFoundException
//	{
//		
//		setName((String)in.readObject());
//		//etc...
//	}

	protected Employee()
	{}
	public Employee(String name, String taxId)
	{
		this(name, taxId, 100);
	}

	public Employee(String name, String taxId, float salary)
	{
		super(name, taxId);
		setSalary(salary);
		ytdSalary = 0;
	}

	/**
	 * Pay this employee its default salary.
	 * 
	 * @return Net pay after taxes
	 */
	@Override
	public float pay()
	{
		System.out.println("Paying " + getName());

		float tax = getSalary() * TAX_RATE;
		ytdSalary += getSalary();
		ytdTax += tax;
		return getSalary() - tax;
	}

	public float getSalary()
	{
		return salary;
	}

	public void setSalary(float salary)
	{
		this.salary = salary;
	}

	public float getYtdSalary()
	{
		return ytdSalary;
	}

	public float getYtdTax()
	{
		return ytdTax;
	}

	@Override
	protected String getTaxIdRegex()
	{
		return "^\\d{3}-\\d\\d-\\d{4}";
	}

}
